import localforage from 'localforage'

const copyToClipboard = (text) => {
    const textArea = document.createElement("textarea")
    textArea.value = text
    document.body.appendChild(textArea)
    textArea.select();
    document.execCommand("copy")
    document.body.removeChild(textArea)

}

const saveLocalData = (key, value, callback=null) => {
    localforage.setItem(key, value).then(res => {
        if (callback) {
            callback(res)

        }
    })
}

const getLocalData = (key, callback = null) => {
    localforage.getItem(key).then(res => {
        if (callback) {
            callback(res)
        }
    })
}

const removeLocalData = (key, callback = null) => {
    localforage.removeItem(key).then(res => {
        if (callback) {
            callback(res)
        }
    })
}


export {
    copyToClipboard,
    getLocalData,
    saveLocalData,
    removeLocalData
}